package sfin.service;

import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import sfin.swt.events.ServiceChangeEvent;
import sfin.swt.events.ServiceChangeListener;
import sfin.swt.util.FormatterUtil;

public abstract class AbstractService {

	protected List<ServiceChangeListener> listeners = new ArrayList<>();
	protected ResourceBundle bundle;
	protected FormatterUtil formatterUtil;
	
	public AbstractService(ResourceBundle bundle, FormatterUtil formatterUtil){
		this.bundle = bundle;
		this.formatterUtil = formatterUtil;
	}
	
	protected void notifyListeners(){
		ServiceChangeEvent event = new ServiceChangeEvent();
		event.service = this;
		for(int i = 0; i<listeners.size(); i++){
			listeners.get(i).changed(event);
		}
	}
	
	public void addListener(ServiceChangeListener listener){
		this.listeners.add(listener);
	}
	
	public void removeListener(ServiceChangeListener listener){
		if(this.listeners.contains(listener))
			this.listeners.remove(listener);
	}

}
	